#!/bin/bash -e

function info() {
    echo Usage: `basename $0` '[-wrm] in.bam'
    exit 1
}

while getopts ":p:f:m:" opt; do
    case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        m) method=$OPTARG;;
        *) info;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

# . $var

# export PATH=~/yn/tools/conda/bin:$PATH
unset PYTHONPATH
. ~/../fei.yang/yn/tools/conda/bin/activate py36
# pip show umi_tools

method=${method:=directional}
mq=${mq:=10}
echo $method

umi_tools dedup \
-I $1 -S $out_prefix.umi.bam \
-L $out_prefix.umi.log \
-E $out_prefix.umi.log \
--output-stats=$out_prefix.umi.stats \
--umi-separator=":" \
--paired \
--method=$method \
--buffer-whole-contig \
-v 10000 \
--mapping-quality=$mq

samtools index $out_prefix.umi.bam


# . $cmd_done
